# -*- encoding: utf-8 -*-

"""
A -- B -- D
|    |
C    E
|  /
F
"""


G = {'A': ['B', 'C'],
     'B': ['A', 'D', 'E'],
     'C': ['A', 'F'],
     'D': ['B'],
     'E': ['B', 'F'],
     'F': ['C', 'E']}


def bfs(graph, start):
    queue, explored = [start], set(start)
    while queue:
        v = queue.pop(0)
        for w in graph[v]:
            if w not in explored:
                explored.add(w)
                queue.append(w)
        print(queue)
    return explored


if __name__ == '__main__':
    print(bfs(G, 'A'))
